#include "scene.h"

#include <QtGui>
#include "gui.h"
#include "ktv/ktv.h"
#include "desktop/desktop.h"
#include "desktop/welcomeanimation.h"

Scene::Scene(GUI *g, int w, int h)
    : QGraphicsScene(-(w-200)/2.0, -(h-200)/2.0, w-200, h-200),
    gui(g), width(w), height(h)
{
    setFocus();

    welcomeAnimation = new WelcomeAnimation(width, height);
    addItem(welcomeAnimation);
    welcomeAnimation->setPos(0, 0);

    desktop = new Desktop(gui, width, height);
    addItem(desktop);
    desktop->setPos(0, 0);
    desktop->setVisible(false);

    ktv = new KTV(gui, width, height);
    addItem(ktv);
    ktv->setPos(0, 0);
    ktv->setVisible(false);

    welcomeAnimation->welcome();
    welcomeAnimation->setFocus();
    gui->setCurrentGui(welcomeAnimation);
//    desktop->setFocus();
//    gui->setCurrentGui(desktop);
//    desktop->setVisible(true);
}

void Scene::launch()
{
    qDebug() << "scene: \t\tshow desktop" << endl;
    welcomeAnimation->setVisible(false);
//    this->removeItem(welcomeAnimation);

    desktop->setVisible(true);
    desktop->setFocus();
    gui->setCurrentGui(desktop);
}

void Scene::initApp(int appIndex)
{
    qDebug() << "scene: app " << appIndex;
    switch (appIndex) {
    case 0:
        launchKTV();
        return;
    case 1:
        qDebug() << "launch speed";
        return;
    case 2:
        qDebug() << "launch ie";
        return;
    case 7:
        qApp->quit();
        return;
    }
}

void Scene::launchDesktop()
{
    invisibleAll();
    qDebug() << "scene: show desktop" << endl;
    desktop->setFocus();
    gui->setCurrentGui(desktop);
    desktop->setVisible(true);
}

void Scene::launchKTV()
{
    invisibleAll();
    qDebug() << "scene: show ktv" << endl;
    ktv->setFocus();
    gui->setCurrentGui(ktv);
    ktv->setVisible(true);
    ktv->launch();
}

void Scene::invisibleAll()
{
    desktop->setVisible(false);
    ktv->setVisible(false);
}

void Scene::setGuiUsable(bool u)
{
    gui->setUsable(u);
}
